<template>
  <li class="video-surveillance">
    <a v-if="isLook" @click.prevent="lookVideo" href="#">视频监控</a>
    <a v-else href="#" @click.prevent="cancelLook">取消查看</a>
  </li>
  <div id="popup-video">
    <div class="close" @click="closeVideo">×</div>
    <video autoplay controls muted poster src="../../../../assets/videos/video.mp4"></video>
  </div>
</template>

<script setup>
import { clickShowVideo } from './Hooks/useClickShowVideo'
import { video_source } from './Hooks/useClickShowVideo'

let map = ref()
onMounted(() => {
  map.value = useGlobalMap()
})

// 是否查看监控
let isLook = ref(true)
let handleMap = ref()
function lookVideo() {
  isLook.value = false
  handleMap.value = clickShowVideo(map.value)
}
function cancelLook() {
  video_source.clear()
  map.value.un('click', handleMap.value)
  isLook.value = true
  let popupVideo = document.querySelector('#popup-video')
  popupVideo.style.display = 'none'
}
function closeVideo() {
  video_source.clear()
  let popupVideo = document.querySelector('#popup-video')
  popupVideo.style.display = 'none'
}
</script>

<style lang="less" scoped>
.video-surveillance {
  padding-top: 3px;
}

a {
  font-size: 16px;
  color: #333;
  text-decoration: none;
}

#popup-video {
  display: none;
  position: fixed;
  left: 20px;
  top: 20px;
  width: 200px;
  height: 200px;
  background-color: #fff;
  border-radius: 5px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
  padding: 3px;
  font-size: 14px;
  color: #333;
  overflow: hidden;
  transition: all 0.3s ease;
  &::before {
    display: block;
    content: '';
    position: absolute;
    bottom: -20px;
    left: 50%;
    transform: translateX(-50%);
    border: 10px solid transparent;
    border-top-color: #000;
  }
  .close {
    position: absolute;
    top: 3px;
    right: 3px;
    font-size: 30px;
    color: red;
    cursor: pointer;
    z-index: 1;
    &:hover {
      color: blue;
    }
  }
  video {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
}
</style>
